package com.cmwa.solution.business.prdSellChannel.controller;

import javax.annotation.Resource;

import org.apache.poi.ss.formula.functions.T;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.cmwa.solution.base.controller.BaseController;
import com.cmwa.solution.base.entity.Page;
import com.cmwa.solution.base.entity.Result;
import com.cmwa.solution.base.entity.SearchParam;
import com.cmwa.solution.business.infodisclosure.institution.service.InstitutionService;
import com.cmwa.solution.business.prdSellChannel.entity.PrdSellChannelVo;
import com.cmwa.solution.business.prdSellChannel.service.PrdSellChannelService;
import com.cmwa.solution.utils.SessionUtils;


/**
 * 销售渠道信息表控制器
 * 
 * @author ex-sujh
 * @date 2019-02-20 09:23:53
 */
@Controller
@RequestMapping("/business/prdSellChannel")
public class PrdSellChannelController extends BaseController {

	private final static String JSP_PATH = "business/prdSellChannel/";
	@Resource
	private PrdSellChannelService prdSellChannelService;
	
	@Resource
	private InstitutionService institutionService;
		
	/**
	 * 跳转到列表页面
	 * @author ex-sujh
	 * @date 2019-02-20 09:23:53
	 * @param model
	 * @return
	 */
	@RequestMapping("/prdSellChannelListView")
	public String prdSellChannelListView(ModelMap model) {
		return JSP_PATH + "prdSellChannelList";
	}
	
	/**
	 * 跳转到销售渠道新增界面
	 * @param model
	 * @param param
	 * @return
	 */
	@RequestMapping("/prdSellChannelAdd")
	public String prdSellChannelAdd(ModelMap model,SearchParam param) { 
		model.addAttribute("instList", institutionService.getInstitutionList(null));
		return JSP_PATH + "prdSellChannelAdd";
	}
	
	@RequestMapping("/prdSellChannelListPage")
	@ResponseBody
	public Page<PrdSellChannelVo> prdSellChannelListPage(SearchParam param) {
		Page<PrdSellChannelVo> list = prdSellChannelService.prdSellChannelListPage(param);
		return list;
	}
	
	@RequestMapping("/addPrdSellChannel")
	public String addPrdSellChannel(PrdSellChannelVo prdSellChannelVo) {
		prdSellChannelVo.setCreateId(SessionUtils.getEmployee().getID());
		prdSellChannelVo.setStatus("S");
		prdSellChannelService.insertPrdSellChannel(prdSellChannelVo);
		return redirectSuccess();
	}
	
	@RequestMapping("/delPrdSellChannel")
	@ResponseBody
	public Result<T> delPrdSellChannel(@RequestParam("channelIds")String channelIds) {
		Result<T> result = new Result<T>();
		try {
			prdSellChannelService.delPrdSellChannelByIds(channelIds);
			result.setSuccess(true);
			result.setMessage("销售渠道信息删除成功！");
		} catch (Exception e) {
			e.printStackTrace();
			result.setSuccess(false);
			result.setMessage("销售渠道信息删除失败！");
		}	
		return result;
	}
	
		
}
